package org.jeecg.modules.demo.baseorde.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.ibatis.annotations.Param;
import org.jeecg.modules.demo.baseorde.entity.BaseOrder;
import org.jeecg.modules.demo.baseorde.entity.BaseOrderCommodityJson;
import org.jeecg.modules.demo.baseorde.entity.BaseOrderInfo;
import org.jeecg.modules.demo.baseorde.mapper.BaseOrderMapper;
import org.jeecg.modules.demo.baseorde.service.IBaseOrderService;
import org.jeecg.modules.util.ToolsUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * @Description: 订单
 * @Author: jeecg-boot
 * @Date: 2022-01-27
 * @Version: V1.0
 */
@Service
public class BaseOrderServiceImpl extends ServiceImpl<BaseOrderMapper, BaseOrder> implements IBaseOrderService {
    @Autowired
    private BaseOrderMapper baseOrderMapper;

    // 查询订单列表
    @Override
    public IPage<BaseOrder> searchOrderList(Page<BaseOrder> page, String stockName, String memberName, String orderCode,
                                            String beginTime, String endTime, String name, String patternPayment, String orderType,
                                            String orderStatus, String storeId) {
        return baseOrderMapper.searchOrderList(page, stockName, memberName, orderCode, beginTime, endTime, name, patternPayment,
                orderType, orderStatus, storeId);
    }

    //查询在线订单列表
    @Override
    public List<BaseOrder> searchOnlineOrderList(String memberName, String orderCode,
                                                 String beginTime, String endTime, String memberPhone,
                                                 String orderStatus, String storeId) {
        return baseOrderMapper.searchOnlineOrderList(memberName, orderCode, beginTime, endTime, memberPhone, orderStatus, storeId);
    }

    // 查询待付款订单数量
    @Override
    public String getPendingPayOrderQty(String storeId) {
        return baseOrderMapper.getPendingPayOrderQty(storeId);
    }

    // 查询退款中订单数量
    @Override
    public String getRefundingOrderQty(String storeId) {
        return baseOrderMapper.getRefundingOrderQty(storeId);
    }

    // 查询今日订单数量
    @Override
    public String getOrderQtyToday(String storeId) {
        //获取今天的日期
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
        String date = sdf.format(new Date());
        String beginTime = date + "00:00:00";
        String endTime = date + "23:59:59";
        return baseOrderMapper.getOrderQtyByTime(storeId, beginTime, endTime);

    }

    @Override
    public String getOrderQtyday(String storeId, String day) {
        //获取今天的日期
        return baseOrderMapper.getOrderQtyByTimes(storeId, day);

    }


    // 查询本月订单数量
    @Override
    public String getOrderQtyThisMonth(String storeId) {
        //获取今天的日期
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
        String beginTime = sdf.format(ToolsUtils.getmindate()) + "00:00:00";
        String endTime = sdf.format(ToolsUtils.getmaxdate()) + "23:59:59";
        return baseOrderMapper.getOrderQtyByTime(storeId, beginTime, endTime);

    }

    // 在线订单自提
    @Override
    public void selfMention(String orderId) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
        String updateTime = sdf.format(ToolsUtils.getmindate());
        baseOrderMapper.selfMention(orderId, updateTime);
    }

    // 在线订单退款
    @Override
    public void refund(String orderId) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
        String updateTime = sdf.format(ToolsUtils.getmindate());
        baseOrderMapper.refund(orderId, updateTime);
    }

    //根据会员id获取订单列表
    @Override
    public List<BaseOrderInfo> getOrderInfoListByMemberId(Integer pageNo, Integer pageSize,
                                                          String storeId, String memberId, String orderStatus) {
        return baseOrderMapper.getOrderInfoListByMemberId(pageNo, pageSize, storeId, memberId, orderStatus);
    }

    @Override
    public void updateConsumeNoticeFlag(@Param("consumeNoticeFlag") Integer consumeNoticeFlag, @Param("id") String id) {
        baseOrderMapper.updateConsumeNoticeFlag(consumeNoticeFlag, id);
    }

    @Override
    public void addCommodityJson(BaseOrderCommodityJson entity) {
        baseOrderMapper.addCommodityJson(entity);
    }
}
